/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package services;

import beans.GetBean;
import java.util.List;
import java.util.Map;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.Produces;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.json.JSONObject;

/**
 * REST Web Service
 *
 * @author tae
 */
@Path("resource/GetMessage")
@Stateless
public class GetMessageResource {

    @Context
    private UriInfo context;
    
    @EJB
    private GetBean getBean;

    /**
     * Creates a new instance of GetMessageResource
     */
    public GetMessageResource() {
    }

    @POST
    @Produces(MediaType.APPLICATION_JSON)
    public String execute(@FormParam("channelID") long channelID)
    {
        System.out.println("getmessage resource executed");
        List<Map<String, Object>> list = getBean.getMessages(channelID);
            
        if(list.size() > 0)
        {
            JSONObject outJSON = new JSONObject();

            outJSON.put("message", list);
            
            return outJSON.toString();
        }
        else
        {
            return "NO_MESSAGE";
        }
    }
}
